﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ThreeByte.ActiveDeck.Config;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;
using System.Collections.ObjectModel;
using log4net;
using System.ComponentModel;
using ThreeByte.ActiveDeck.Content;

namespace ThreeByte.ActiveDeck.AddIn.Controls.Wizard.Pages
{
    /// <summary>
    /// Interaction logic for SelectPhotoPage.xaml
    /// </summary>
    public partial class SelectPhotoPage : Page, INotifyPropertyChanged
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(SelectPhotoPage));
        private CoreConfig Config;

        public SelectPhotoPage() {
            InitializeComponent();

            Config = WizardMainFrame.ActiveConfig;
        }


        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string propertyName) {
            if(PropertyChanged != null) {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

  
        

        private void NextButton_Click(object sender, RoutedEventArgs e) {
           
        }

        private void CannotExecute(object sender, CanExecuteRoutedEventArgs e) {
            e.CanExecute = false;
            e.Handled = true;
        }

        private void HelpExecuted(object sender, ExecutedRoutedEventArgs e) {

        }

        private void SelectPhoto_Click(object sender, RoutedEventArgs e) {
            //Open a file browser dialog
            System.Windows.Forms.OpenFileDialog fileDialog = new System.Windows.Forms.OpenFileDialog();
            fileDialog.CheckFileExists = true;
            fileDialog.Filter = "Image Files (*.jpg;*.png)|*.bmp;*.jpg;*.jpeg;*.png|All files (*.*)|*.*";
            System.Windows.Forms.DialogResult result = fileDialog.ShowDialog();
            if(result != System.Windows.Forms.DialogResult.OK) {
                return;
            }

            string filePath = fileDialog.FileName;
            string fileName = fileDialog.SafeFileName;

            //Construct two UserSlide configs?
            GraphicResource image = new GraphicResource(fileName, new Uri(filePath), ImageType.JPEG);//Store Backgrounds as JPEGS

            //One preview
            UserSlideConfig fillConfig = new UserSlideConfig();
            fillConfig.Name = string.Format("Photo_{0}", fileName);
            fillConfig.Image = image;
            fillConfig.ScaleToFill = true;
            fillConfig.ZoomEnabled = true;  //For effect
            FillPreviewRoot.Content = PagePreviewFactory.Create(fillConfig);
            FillButton.Tag = fillConfig;

            //The other
            UserSlideConfig fitConfig = new UserSlideConfig();
            fitConfig.Name = string.Format("Photo_{0}", fileName);
            fitConfig.Image = image;
            fitConfig.ScaleToFill = false;
            FitPreviewRoot.Content = PagePreviewFactory.Create(fitConfig);
            FitButton.Tag = fitConfig;

            FileNameTextBox.Text = System.IO.Path.GetFileName(fileName);
        }

        private void ChoosePhoto_Click(object sender, RoutedEventArgs e) {
            UserSlideConfig config = (UserSlideConfig)((Button)sender).Tag;
            if(config != null) {
                NavigationService navService = this.NavigationService;
                if(navService != null) {
                    navService.Navigate(new PhotoAssignmentPage(config));
                }
            }

        }
        
    }
}
